package leetcode.code0961;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int repeatedNTimes(int[] nums) {
		int len = nums.length, r = len, n = len >> 1;
		while (true) {
			int index = (int) (Math.random() * r);
			int cnt = 0, num = nums[index];
			for (int i = 0; i < r; i++) {
				if (nums[i] == num) {
					cnt++;
				}
			}
			if (cnt == n) {
				return num;
			}
			nums[index] = nums[r - 1];
			r--;
		}
	}

	@Override
	public void debug4() {
		H.compare(3, this.repeatedNTimes(H.str2array3("[1,2,3,3]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
